<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="开始时间" prop="date">
        <el-date-picker v-model="queryParams.date" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['water:qt-original:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['water:qt-original:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="开始时间" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="色（度）" align="center" prop="color" />
      <el-table-column label="嗅和味" align="center" prop="taste" />
      <el-table-column label="水温" align="center" prop="waterTemp" />
      <el-table-column label="浑浊度" align="center" prop="turbidity" />
      <el-table-column label="PH" align="center" prop="ph" />
      <el-table-column label="肉眼可见物" align="center" prop="visible" />
      <el-table-column label="亚硝酸盐氮" align="center" prop="no3N" />
      <el-table-column label="COD" align="center" prop="cod" />
      <el-table-column label="氨氮" align="center" prop="nh3N" />
      <el-table-column label="总大肠菌群" align="center" prop="coliforms" />
      <el-table-column label="耐热大肠菌群" align="center" prop="thermostableColiforms" />
      <el-table-column label="细菌总数" align="center" prop="bacteria" />
      <el-table-column label="总硬度" align="center" prop="hardness" />
      <el-table-column label="氯化物" align="center" prop="chloride" />
      <el-table-column label="铁" align="center" prop="fe" />
      <el-table-column label="挥发酚" align="center" prop="volatilePhenol" />
      <el-table-column label="锰" align="center" prop="mn" />
      <el-table-column label="砷" align="center" prop="arsenic" />
      <el-table-column label="铬" align="center" prop="cr" />
      <el-table-column label="氰化物" align="center" prop="kcn" />
      <el-table-column label="总磷" align="center" prop="p" />
      <el-table-column label="藻类	" align="center" prop="algae" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['water:qt-original:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['water:qt-original:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="500px" v-dialogDrag append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="开始时间" prop="date">
          <el-date-picker clearable v-model="form.date" type="date" value-format="timestamp" placeholder="选择开始时间" />
        </el-form-item>
        <el-form-item label="色（度）" prop="color">
          <el-input v-model="form.color" placeholder="请输入色（度）" />
        </el-form-item>
        <el-form-item label="嗅和味" prop="taste">
          <el-input v-model="form.taste" placeholder="请输入嗅和味" />
        </el-form-item>
        <el-form-item label="水温" prop="waterTemp">
          <el-input v-model="form.waterTemp" placeholder="请输入水温" />
        </el-form-item>
        <el-form-item label="浑浊度" prop="turbidity">
          <el-input v-model="form.turbidity" placeholder="请输入浑浊度" />
        </el-form-item>
        <el-form-item label="PH" prop="ph">
          <el-input v-model="form.ph" placeholder="请输入PH" />
        </el-form-item>
        <el-form-item label="肉眼可见物" prop="visible">
          <el-input v-model="form.visible" placeholder="请输入肉眼可见物" />
        </el-form-item>
        <el-form-item label="亚硝酸盐氮" prop="no3N">
          <el-input v-model="form.no3N" placeholder="请输入亚硝酸盐氮" />
        </el-form-item>
        <el-form-item label="COD" prop="cod">
          <el-input v-model="form.cod" placeholder="请输入COD" />
        </el-form-item>
        <el-form-item label="氨氮" prop="nh3N">
          <el-input v-model="form.nh3N" placeholder="请输入氨氮" />
        </el-form-item>
        <el-form-item label="总大肠菌群" prop="coliforms">
          <el-input v-model="form.coliforms" placeholder="请输入总大肠菌群" />
        </el-form-item>
        <el-form-item label="耐热大肠菌群" prop="thermostableColiforms">
          <el-input v-model="form.thermostableColiforms" placeholder="请输入耐热大肠菌群" />
        </el-form-item>
        <el-form-item label="细菌总数" prop="bacteria">
          <el-input v-model="form.bacteria" placeholder="请输入细菌总数" />
        </el-form-item>
        <el-form-item label="总硬度" prop="hardness">
          <el-input v-model="form.hardness" placeholder="请输入总硬度" />
        </el-form-item>
        <el-form-item label="氯化物" prop="chloride">
          <el-input v-model="form.chloride" placeholder="请输入氯化物" />
        </el-form-item>
        <el-form-item label="铁" prop="fe">
          <el-input v-model="form.fe" placeholder="请输入铁" />
        </el-form-item>
        <el-form-item label="挥发酚" prop="volatilePhenol">
          <el-input v-model="form.volatilePhenol" placeholder="请输入挥发酚" />
        </el-form-item>
        <el-form-item label="锰" prop="mn">
          <el-input v-model="form.mn" placeholder="请输入锰" />
        </el-form-item>
        <el-form-item label="砷" prop="arsenic">
          <el-input v-model="form.arsenic" placeholder="请输入砷" />
        </el-form-item>
        <el-form-item label="铬" prop="cr">
          <el-input v-model="form.cr" placeholder="请输入铬" />
        </el-form-item>
        <el-form-item label="氰化物" prop="kcn">
          <el-input v-model="form.kcn" placeholder="请输入氰化物" />
        </el-form-item>
        <el-form-item label="总磷" prop="p">
          <el-input v-model="form.p" placeholder="请输入总磷" />
        </el-form-item>
        <el-form-item label="藻类	" prop="algae">
          <el-input v-model="form.algae" placeholder="请输入藻类	" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { createQtOriginal, updateQtOriginal, deleteQtOriginal, getQtOriginal, getQtOriginalPage, exportQtOriginalExcel } from "@/api/water/qtOriginal";

export default {
  name: "QtOriginal",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原水记录列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        date: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getQtOriginalPage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        date: undefined,
        color: undefined,
        taste: undefined,
        waterTemp: undefined,
        turbidity: undefined,
        ph: undefined,
        visible: undefined,
        no3N: undefined,
        cod: undefined,
        nh3N: undefined,
        coliforms: undefined,
        thermostableColiforms: undefined,
        bacteria: undefined,
        hardness: undefined,
        chloride: undefined,
        fe: undefined,
        volatilePhenol: undefined,
        mn: undefined,
        arsenic: undefined,
        cr: undefined,
        kcn: undefined,
        p: undefined,
        algae: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加原水记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getQtOriginal(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改原水记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateQtOriginal(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createQtOriginal(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除原水记录编号为"' + id + '"的数据项?').then(function() {
          return deleteQtOriginal(id);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有原水记录数据项?').then(() => {
          this.exportLoading = true;
          return exportQtOriginalExcel(params);
        }).then(response => {
          this.$download.excel(response, '原水记录.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
